package com.hmall.item.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.Result;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private IItemService itemService;
    //分页查询
    @GetMapping("list")
    public PageDTO findAll(@RequestParam("page") Long page,@RequestParam("size") Long size){
       return itemService.findAll(page,size);
    }
    //根据id查询
    @GetMapping("/{id}")
    public Item findById(@PathVariable("id") Long id){
        return itemService.findById(id);
    }
    //新增
    @PostMapping
    public Result add(@RequestBody Item item){
        return itemService.add(item);
    }
    //商品上架下架
    @PutMapping("/status/{id}/{status}")
    public Result putItem(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        return itemService.putItem(id,status);
    }
    //修改商品
    @PutMapping
    public Result update(@RequestBody Item item) {
        return itemService.updateItem(item);
    }
    //删除菜品
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return itemService.deleteById(id);
    }
    //库存减少
    @GetMapping
    public Integer Inventory (@RequestParam("id") Long id,@RequestParam("num") Long num){
        return itemService.Inventory(id,num);
    }


}
